﻿using System.Collections.Generic;
using System.Linq;
using XRM.Security.DataAccess.Models;
using XRM.Security.WebUI.Models.CertRegister;

namespace XRM.Security.WebUI.Helpers
{
    public static class ViewModelHelper
    {
        public static List<CertSearchItem> ToSearchItems( this IQueryable<CertRegister> query )
        {
            return query.Select( item => new CertSearchItem
            {
                Id = item.CertRegisterId,
                FromDate = item.FromDate,
                ToDate = item.ToDate,
                UserLastName = item.UserRegister.LastName,
                UserFirstName = item.UserRegister.FirstName,
                UserMiddleName = item.UserRegister.MotherName,
                SerialNumber = item.SerialNumber,
                SerialNumberEtoken = item.SerialNumberEtoken,
                PCSerialNumber = item.PC.SerialNumber,
                IdentityCenterName = item.IdentityCenter.IdentityCenterName,
                UserId = item.UserRegister.UserRegisterId,
                UserStatus = item.UserRegister.Status,
                InfoSystems = item.CertRegisterInfoSystems.Select( s => s.InfoSystem.InfoSystemName ).OrderBy(s => s).ToList(),
                RequestId = item.RequestId,
                RequestNumber = item.Request.Number
            } ).ToList();
        }
    }
}